package com.example.shoppingdemo.nslcommodity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.example.shoppingdemo.R;
import com.example.shoppingdemo.nslcommodity.IResult.CommodityRs;
import com.example.shoppingdemo.nslcommodity.IResult.ICommodityResult;
import com.example.shoppingdemo.nslcommodity.fragment.AllFragment;
import com.example.shoppingdemo.nslcommodity.fragment.CloseFragment;
import com.example.shoppingdemo.nslcommodity.fragment.ConsignmentFragment;
import com.example.shoppingdemo.nslcommodity.fragment.EstimateFragment;
import com.example.shoppingdemo.nslcommodity.fragment.InvalidFragment;
import com.example.shoppingdemo.nslcommodity.fragment.PaymentFragment;
import com.example.shoppingdemo.nslcommodity.fragment.ReceivingFragment;
import com.example.shoppingdemo.nslcommodity.fragment.ViewPagerAdapter;
import com.example.shoppingdemo.nslcommodity.javabean.CommodityListModel;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;

/**
 * 我的订单页面
 */
public class WeOrderForm extends AppCompatActivity {
    private TabLayout tabLayout;
    private List<Fragment> fragmentList;
    private ViewPager viewPager;
    private List<String> titleList;
    private ViewPagerAdapter adapter;
    int type;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_we_order_form);
        Intent intent=getIntent();
        type=intent.getIntExtra("id",-1);
        ImageView back=findViewById(R.id.image_we_back);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        initView();
    }
    /**
     * 初始化TabLayout，ViewPager，并且把TabLayout和ViewPager联系起来
     */
    private void initView(){
        tabLayout = findViewById(R.id.tab_layout);
        viewPager = findViewById(R.id.view_pager);
        initData();
        adapter = new ViewPagerAdapter(getSupportFragmentManager(),fragmentList,titleList);
        viewPager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewPager);
        tabLayout.selectTab(tabLayout.getTabAt(type));
    }

    /**
     * 初始化Fragment，给TabLayout数据
     */
    private void initData(){
        titleList = new ArrayList<>();
        titleList.add("全部");
        titleList.add("待付款");
        titleList.add("待发货");
        titleList.add("已发货");
        titleList.add("已完成");
        titleList.add("已关闭");
        titleList.add("无效订单");
        fragmentList = new ArrayList<>();
        fragmentList.add(new AllFragment());
        fragmentList.add(new PaymentFragment());
        fragmentList.add(new ConsignmentFragment());
        fragmentList.add(new ReceivingFragment());
        fragmentList.add(new EstimateFragment());
        fragmentList.add(new CloseFragment());
        fragmentList.add(new InvalidFragment());
    }
}